﻿Public Class clsSzukanie

#Region "Attributes"

    Private mvarMaterial As Collection(Of clsInhMaterial)
    Private mvarWaluta As Collection(Of clsInhWaluta)
    Private mvarDostawca As New Collection(Of clsInhDostawca)
    Private mvarGatunek As Collection(Of clsInhGatunek)

    Private mvarPracownik As Collection(Of clsInhPracownik)

    Private mvarSwiadectwa As Collection(Of clsInhSwiadectwo)
#End Region

#Region "Properties"

    Public Property Materialy() As Collection(Of clsInhMaterial)
        Get
            Return mvarMaterial
        End Get
        Set(ByVal value As Collection(Of clsInhMaterial))
            mvarMaterial = value
        End Set
    End Property

    Public Property Waluty() As Collection(Of clsInhWaluta)
        Get
            Return mvarWaluta
        End Get
        Set(ByVal value As Collection(Of clsInhWaluta))
            mvarWaluta = value
        End Set
    End Property

    Public Property Dostawca() As Collection(Of clsInhDostawca)
        Get
            Return mvarDostawca
        End Get
        Set(ByVal value As Collection(Of clsInhDostawca))
            mvarDostawca = value
        End Set
    End Property

    Public Property Gatunek() As Collection(Of clsInhGatunek)
        Get
            Return mvarGatunek
        End Get
        Set(ByVal value As Collection(Of clsInhGatunek))
            mvarGatunek = value
        End Set
    End Property

    Public Property Pracownik() As Collection(Of clsInhPracownik)
        Get
            Return mvarPracownik
        End Get
        Set(ByVal value As Collection(Of clsInhPracownik))
            mvarPracownik = value
        End Set
    End Property

    Public Property Swiadectwa() As Collection(Of clsInhSwiadectwo)
        Get
            Return mvarSwiadectwa
        End Get
        Set(ByVal value As Collection(Of clsInhSwiadectwo))
            mvarSwiadectwa = value
        End Set
    End Property

#End Region

#Region "Methods"

    Public Sub New()
        mvarMaterial = New Collection(Of clsInhMaterial)
        mvarWaluta = New Collection(Of clsInhWaluta)
        mvarDostawca = New Collection(Of clsInhDostawca)
        mvarGatunek = New Collection(Of clsInhGatunek)
        mvarPracownik = New Collection(Of clsInhPracownik)
        mvarSwiadectwa = New Collection(Of clsInhSwiadectwo)
    End Sub

    Public Sub SzukajMaterialu(ByVal lvarDbHolder As clsDataBase, ByVal Zapytanie As String)

        Dim lvarZapytanie As String

        lvarZapytanie = Zapytanie

        Dim lvarReader As OdbcDataReader = Nothing
        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_oem", "cls_szukanie", 1, VAR_ERROR_HANDLER)

            With lvarSqlRunner
                .AddParameter("p_zapytanie", Zapytanie)
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                While lvarReader.Read
                    mvarMaterial.Add(New clsInhMaterial(CInt(IIf(IsDBNull(lvarReader.Item("id")), -1, lvarReader.Item("id"))), lvarDbHolder))
                End While
            End If

        End If

    End Sub

    Public Sub SzukajWaluty(ByVal lvarDbHolder As clsDataBase, ByVal Zapytanie As String)

        Dim lvarZapytanie As String

        lvarZapytanie = Zapytanie

        Dim lvarReader As OdbcDataReader = Nothing
        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_oem", "cls_szukanie", 2, VAR_ERROR_HANDLER)

            With lvarSqlRunner
                .AddParameter("p_zapytanie", Zapytanie)
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                While lvarReader.Read
                    mvarWaluta.Add(New clsInhWaluta(CInt(IIf(IsDBNull(lvarReader.Item("id")), -1, lvarReader.Item("id"))), lvarDbHolder))
                End While
            End If

        End If

    End Sub

    Public Sub SzukajDostawcy(ByVal lvarDbHolder As clsDataBase, ByVal Zapytanie As String)

        Dim lvarReader As OdbcDataReader = Nothing
        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_oem", "cls_szukanie", 3, VAR_ERROR_HANDLER)
            With lvarSqlRunner
                .AddParameter("p_zapytanie", Zapytanie)
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                While lvarReader.Read
                    mvarDostawca.Add(New clsInhDostawca(CInt(IIf(IsDBNull(lvarReader.Item("id")), -1, lvarReader.Item("id"))), lvarDbHolder))
                End While
            End If
        End If

    End Sub

    Public Sub SzukajGatunku(ByVal lvarDbHolder As clsDataBase, ByVal Zapytanie As String)

        Dim lvarReader As OdbcDataReader = Nothing
        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_oem", "cls_szukanie", 4, VAR_ERROR_HANDLER)
            With lvarSqlRunner
                .AddParameter("p_zapytanie", Zapytanie)
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                While lvarReader.Read
                    mvarGatunek.Add(New clsInhGatunek(CInt(IIf(IsDBNull(lvarReader.Item("id")), -1, lvarReader.Item("id"))), lvarDbHolder))
                End While
            End If
        End If

    End Sub

    Public Sub SzukajPracownika(ByVal lvarDbHolder As clsDataBase, ByVal Zapytanie As String)

        Dim lvarReader As OdbcDataReader = Nothing
        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_oem", "cls_szukanie", 5, VAR_ERROR_HANDLER)
            With lvarSqlRunner
                .AddParameter("p_zapytanie", Zapytanie)
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                While lvarReader.Read
                    mvarPracownik.Add(New clsInhPracownik(CInt(IIf(IsDBNull(lvarReader.Item("id")), -1, lvarReader.Item("id"))), lvarDbHolder))
                End While
            End If
        End If

    End Sub

    Public Sub SzukajSwiadectw(ByVal lvarDbHolder As clsDataBase, ByVal Zapytanie As String)

        Dim lvarReader As OdbcDataReader = Nothing
        If lvarDbHolder.IsOpen Then
            Dim lvarSqlRunner As New clsSqlRunner(lvarDbHolder, "queries_application_oem", "cls_szukanie", 6, VAR_ERROR_HANDLER)
            With lvarSqlRunner
                .AddParameter("p_id", Zapytanie)
                lvarReader = .ExecuteQuery
            End With

            If lvarReader.HasRows Then
                While lvarReader.Read
                    mvarSwiadectwa.Add(New clsInhSwiadectwo(CInt(IIf(IsDBNull(lvarReader.Item("id")), -1, lvarReader.Item("id"))), lvarDbHolder))
                End While
            End If
        End If

    End Sub

#End Region

End Class
